package com.thread.book.book2;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class SyBarr01 {

    public static void main(String[] args) {
        CyclicBarrier cb = new CyclicBarrier(2, () -> System.out.println("优先输出"));
        new Thread(() -> {
            try {
                cb.await();
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("第一个");
        }).start();
        new Thread(() -> {
            try {
                cb.await();
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("第二个");
        }).start();
        System.out.println("一起开始");
    }
}
